import numpy as np
import tensorflow as tf
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import OneHotEncoder
import matplotlib.pyplot as plt

# load data
path = r'../../../../large_data/ML1/hand_writing/'
y = np.loadtxt(path + 'labely.txt', delimiter=',')
np.random.seed(666)
np.random.shuffle(y)
n_cls = len(np.unique(y))
print('n_cls', n_cls)

# placeholder
ph_y = tf.placeholder(tf.int32, [None], 'placeholder_y')
print(ph_y)
y_oh = tf.reshape(tf.one_hot(ph_y, n_cls), [-1, n_cls], name='y_one_hot')
print(y_oh)
y_indices = tf.argmax(y_oh, axis=1, name='y_indices')
print(y_indices)

with tf.compat.v1.Session() as sess:
    sess.run(tf.compat.v1.global_variables_initializer())
    y_oh_v, y_indices_v = sess.run([y_oh, y_indices], feed_dict={ph_y: y})
    k = 5
    print(y_oh_v[:k])
    print(y_indices_v[:k])
